namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update0009 : DbMigration
    {
        public override void Up()
        {
            RenameTable(name: "dbo.hrm_job_site", newName: "hrm_mp_job_sites");
            RenameTable(name: "dbo.hrm_executive_position", newName: "hrm_mp_exec_positions");
            RenameTable(name: "dbo.HrmMpClass", newName: "hrm_mp_classes");
            RenameTable(name: "dbo.tablename", newName: "rule_approve_type");
            DropForeignKey("dbo.hrm_ps_employees", "class_seq", "dbo.hrm_mas_class");
            DropForeignKey("dbo.hrm_mas_class", "pos_type_seq", "dbo.HrmMasPositionType");
            DropForeignKey("dbo.hrm_mas_class", "emp_type_seq", "dbo.hrm_mas_employee_type");
            DropForeignKey("dbo.HrmPsCommandDtls", "OldClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmPsCommandDtls", "NewClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmPsCommandDtls", "EntClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmMpFieldDuty", "ClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmMpFieldSpecificationDtls", "ClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmMpFieldSpecification", "ClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "ClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmPsRoyalItemRequest", "ClassId", "dbo.hrm_mas_class");
            DropForeignKey("dbo.HrmPrSalaryGroup", "ClassId", "dbo.hrm_mas_class");
            DropIndex("dbo.hrm_ps_employees", new[] { "class_seq" });
            DropIndex("dbo.hrm_mas_class", new[] { "pos_type_seq" });
            DropIndex("dbo.hrm_mas_class", new[] { "emp_type_seq" });
            DropIndex("dbo.HrmPsCommandDtls", new[] { "OldClassId" });
            DropIndex("dbo.HrmPsCommandDtls", new[] { "NewClassId" });
            DropIndex("dbo.HrmPsCommandDtls", new[] { "EntClassId" });
            DropIndex("dbo.HrmMpFieldDuty", new[] { "ClassId" });
            DropIndex("dbo.HrmMpFieldSpecificationDtls", new[] { "ClassId" });
            DropIndex("dbo.HrmMpFieldSpecification", new[] { "ClassId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdClassId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "ClassId" });
            DropIndex("dbo.HrmPsRoyalItemRequest", new[] { "ClassId" });
            DropIndex("dbo.HrmPrSalaryGroup", new[] { "ClassId" });
            RenameColumn(table: "dbo.mas_name_prefixes", name: "gender_code", newName: "prefix_code");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "gender_name", newName: "prefix_name");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "name_eng", newName: "prefix_name_eng");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "name_short", newName: "prefix_short");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "name_eng_short", newName: "prefix_short_eng");
            RenameColumn(table: "dbo.hrm_mp_positions", name: "pos_no", newName: "pos_ref");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "ClassId", newName: "class_seq");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "ClassNo", newName: "class_no");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "ClassName", newName: "class_name");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "ClassNameShort", newName: "class_name_short");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "ClassEng", newName: "class_eng");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "ClassEngShort", newName: "class_eng_short");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "PosTypeId", newName: "pos_type_seq");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "EmpTypeId", newName: "emp_type_seq");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "RecordStatus", newName: "record_status");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "CreatedBy", newName: "created_by");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "CreatedWhen", newName: "created_when");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "UpdatedBy", newName: "updated_by");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "UpdatedWhen", newName: "updated_when");
            AlterColumn("dbo.hrm_mp_classes", "remarks", c => c.String());
            AddForeignKey("dbo.hrm_ps_employees", "class_seq", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsCommandDtls", "OldClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsCommandDtls", "NewClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsCommandDtls", "EntClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmMpFieldDuty", "ClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmMpFieldSpecificationDtls", "ClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmMpFieldSpecification", "ClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "ClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsRoyalItemRequest", "ClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPrSalaryGroup", "ClassId", "dbo.hrm_mp_classes", "class_seq");
            CreateIndex("dbo.hrm_ps_employees", "class_seq");
            CreateIndex("dbo.HrmPsCommandDtls", "OldClassId");
            CreateIndex("dbo.HrmPsCommandDtls", "NewClassId");
            CreateIndex("dbo.HrmPsCommandDtls", "EntClassId");
            CreateIndex("dbo.HrmMpFieldDuty", "ClassId");
            CreateIndex("dbo.HrmMpFieldSpecificationDtls", "ClassId");
            CreateIndex("dbo.HrmMpFieldSpecification", "ClassId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdClassId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "ClassId");
            CreateIndex("dbo.HrmPsRoyalItemRequest", "ClassId");
            CreateIndex("dbo.HrmPrSalaryGroup", "ClassId");
            DropTable("dbo.hrm_mas_class");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.hrm_mas_class",
                c => new
                    {
                        class_seq = c.Int(nullable: false, identity: true),
                        class_no = c.String(),
                        class_name = c.String(),
                        name_short = c.String(),
                        name_eng = c.String(),
                        name_eng_short = c.String(),
                        pos_type_seq = c.Int(nullable: false),
                        emp_type_seq = c.Int(nullable: false),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                    })
                .PrimaryKey(t => t.class_seq);
            
            DropIndex("dbo.HrmPrSalaryGroup", new[] { "ClassId" });
            DropIndex("dbo.HrmPsRoyalItemRequest", new[] { "ClassId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "ClassId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdClassId" });
            DropIndex("dbo.HrmMpFieldSpecification", new[] { "ClassId" });
            DropIndex("dbo.HrmMpFieldSpecificationDtls", new[] { "ClassId" });
            DropIndex("dbo.HrmMpFieldDuty", new[] { "ClassId" });
            DropIndex("dbo.HrmPsCommandDtls", new[] { "EntClassId" });
            DropIndex("dbo.HrmPsCommandDtls", new[] { "NewClassId" });
            DropIndex("dbo.HrmPsCommandDtls", new[] { "OldClassId" });
            DropIndex("dbo.hrm_ps_employees", new[] { "class_seq" });
            DropForeignKey("dbo.HrmPrSalaryGroup", "ClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmPsRoyalItemRequest", "ClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "ClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmMpFieldSpecification", "ClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmMpFieldSpecificationDtls", "ClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmMpFieldDuty", "ClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmPsCommandDtls", "EntClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmPsCommandDtls", "NewClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.HrmPsCommandDtls", "OldClassId", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.hrm_ps_employees", "class_seq", "dbo.hrm_mp_classes");
            AlterColumn("dbo.hrm_mp_classes", "Remarks", c => c.String());
            RenameColumn(table: "dbo.hrm_mp_classes", name: "updated_when", newName: "UpdatedWhen");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "updated_by", newName: "UpdatedBy");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "created_when", newName: "CreatedWhen");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "created_by", newName: "CreatedBy");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "record_status", newName: "RecordStatus");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "emp_type_seq", newName: "EmpTypeId");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "pos_type_seq", newName: "PosTypeId");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "class_eng_short", newName: "ClassEngShort");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "class_eng", newName: "ClassEng");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "class_name_short", newName: "ClassNameShort");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "class_name", newName: "ClassName");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "class_no", newName: "ClassNo");
            RenameColumn(table: "dbo.hrm_mp_classes", name: "class_seq", newName: "ClassId");
            RenameColumn(table: "dbo.hrm_mp_positions", name: "pos_ref", newName: "pos_no");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "prefix_short_eng", newName: "name_eng_short");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "prefix_short", newName: "name_short");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "prefix_name_eng", newName: "name_eng");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "prefix_name", newName: "gender_name");
            RenameColumn(table: "dbo.mas_name_prefixes", name: "prefix_code", newName: "gender_code");
            CreateIndex("dbo.HrmPrSalaryGroup", "ClassId");
            CreateIndex("dbo.HrmPsRoyalItemRequest", "ClassId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "ClassId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdClassId");
            CreateIndex("dbo.HrmMpFieldSpecification", "ClassId");
            CreateIndex("dbo.HrmMpFieldSpecificationDtls", "ClassId");
            CreateIndex("dbo.HrmMpFieldDuty", "ClassId");
            CreateIndex("dbo.HrmPsCommandDtls", "EntClassId");
            CreateIndex("dbo.HrmPsCommandDtls", "NewClassId");
            CreateIndex("dbo.HrmPsCommandDtls", "OldClassId");
            CreateIndex("dbo.hrm_mas_class", "emp_type_seq");
            CreateIndex("dbo.hrm_mas_class", "pos_type_seq");
            CreateIndex("dbo.hrm_ps_employees", "class_seq");
            AddForeignKey("dbo.HrmPrSalaryGroup", "ClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmPsRoyalItemRequest", "ClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "ClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmMpFieldSpecification", "ClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmMpFieldSpecificationDtls", "ClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmMpFieldDuty", "ClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmPsCommandDtls", "EntClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmPsCommandDtls", "NewClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.HrmPsCommandDtls", "OldClassId", "dbo.hrm_mas_class", "class_seq");
            AddForeignKey("dbo.hrm_mas_class", "emp_type_seq", "dbo.hrm_mas_employee_type", "emp_type_seq", cascadeDelete: true);
            AddForeignKey("dbo.hrm_mas_class", "pos_type_seq", "dbo.HrmMasPositionType", "PosTypeId", cascadeDelete: true);
            AddForeignKey("dbo.hrm_ps_employees", "class_seq", "dbo.hrm_mas_class", "class_seq");
            RenameTable(name: "dbo.rule_approve_type", newName: "tablename");
            RenameTable(name: "dbo.hrm_mp_classes", newName: "HrmMpClass");
            RenameTable(name: "dbo.hrm_mp_exec_positions", newName: "hrm_executive_position");
            RenameTable(name: "dbo.hrm_mp_job_sites", newName: "hrm_job_site");
        }
    }
}
